grammar TTCN;

WS
	:[ \n\r\t]+ -> skip
	;

fragment
LETER_LITERAL
	:'A'..'Z'
	|'a'..'z'
	;
fragment
DIGIT_LITERAL
	:[0-9]
	;
STATEND
	:';'
	;
	
PRIMITIVE
	:'integer'
	|'universal'* 'char'
	|'float'
	|'boolean'
	|'objid'
	|'verdicttype'
	;

PRIMITIVESTRING
	:'bitstring'
	|'hexstring'
	|'octetstring'
	|'universal'* 'charstring'
	;	

CHAR_LITERAL
	:'"'LETER_LITERAL'"'
	;
	
INTEGER_LITERAL
	:DIGIT_LITERAL+
	|'-'DIGIT_LITERAL+
	;
	
FLOAT_LITERAL
	:DIGIT_LITERAL'.'DIGIT_LITERAL+
	|'-'DIGIT_LITERAL'.'DIGIT_LITERAL+
	;

BOOLEAN_LITERAL
	:'true'
	|'false'
	;

VERDICTTYPE_LITERAL
	:'none'
	|'error'
	|'fail'
	|'inconc'
	|'pass'
	;
BITSTRING_LITERAL	
	:'\''[01]+'\'B'
	;
HEXSTRING_LITERAL	
	:'\''[0-9A-F]+'\'B'
	;	
OCTETSTRING_LITERAL
	:'\''[0-9A-F]+'\'O'
	;
CHARSTRING_LITERAL
	:'"'(~[\n\r]|'""')*'"' 
	;
	/*Escape a sequential double quotes. E.g. "Hello ""Junior"" X!", effected result will be /Hello "Junior" X!/*/
/*KW_LITERAL
	:
	('action'
	|'address'
	|'all'
	|'alt'
	|'fail'
	|'for'
	|'from'
	|'noblock'
	|'not'
	|'no 4b'
	|'no'
	|'self'
	|'set'
	|'activate'
	|'altstep'
	|'and'
	|'and4b'
	|'any'
	|'anytype'
	|'bitstring'
	|'boolean'
	|'call'
	|'catch'
	|'char'
	|'charstring'
	|'check'
	|'clear'
	|'complement'
	|'component'
	|'connect'
	|'const'
	|'control'
	|'create'
	|'deactivate'
	|'default'
	|'disconnect'
	|'display'
	|'do'
	|'done'
	|'else'
	|'encode'
	|'enumerated'
	|'error'
	|'except'
	|'exception'
	|'execute'
	|'extension'
	|'external'
	|'fail'
	|'false'
	|'float'
	|'function '
	|'getverdict'
	|'getcall'
	|'getreply'
	|'goto'
	|'group'
	|'hexstring'
	|'if'
	|'ifpresent'
	|'import'
	|'in'
	|'inconc'
	|'infinity'
	|'inout'
	|'integer'
	|'interleave'
	|'label'
	|'language'
	|'length'
	|'log'
	|'map'
	|'match'
	|'message'
	|'mixed'
	|'mod'
	|'modifies'
	|'module'
	|'mtc'
	|'none'
	|'t'
	|'wait'
	|'null'
	|'objid'
	|'octetstring'
	|'of'
	|'omit'
	|'on'
	|'optional'
	|'or'
	|'or4b'
	|'out'
	|'override'
	|'param'
	|'Modulepar'
	|'pass'
	|'pattern'
	|'port'
	|'procedure'
	|'raise'
	|'read'
	|'receive'
	|'record'
	|'recursive '
	|'rem'
	|'repeat'
	|'reply'
	|'return '
	|'running'
	|'runs'
	|'send'
	|'sender'
	|'setverdict'
	|'signature'
	|'start'
	|'stop'
	|'subset'
	|'superset'
	|'system '
	|'template'
	|'testcase'
	|'timeout'
	|'timer'
	|'to'
	|'trigger'
	|'true'
	|'type'
	|'union'
	|'universal'
	|'unmap'
	|'value'
	|'valueof'
	|'var'
	|'variant'
	|'verdicttype'
	|'while'
	|'with'
	|'xor'
	|'xor4b' 
	){System.out.println("KW matched " + _text + " " + _type + " "+_tokenStartCharIndex);}
	;
*/	
ID 
	:LETER_LITERAL+ 
		(LETER_LITERAL
		|DIGIT_LITERAL
		|'_'
		)* {System.out.println("ID matched " + _text + " " + _type + " "+_tokenStartCharIndex);}
	;
	
ASSIGN
	:':='
	;
intDec
	:'integer' ID
	;
floatDec
	:'float' ID
	;
booleanDec
	:'boolean' ID
	;
bitstringDec
	:'bitstring' ID
	;
hexstringDec
	:'hexstring' ID
	;
octetstringDec
	:'octetstring' ID
	;
charDec
	:'universal'* 'char' ID
	;
charstringDec
	:'universal'* 'charstring' ID
	;
objidDec
	:'objid' ID
	;
basicTypeDef
	:'type' 
		(intDec (ASSIGN INTEGER_LITERAL)*?
		|floatDec (ASSIGN FLOAT_LITERAL)*?
		|booleanDec (ASSIGN BOOLEAN_LITERAL)*?
		|bitstringDec (ASSIGN BITSTRING_LITERAL)*?
		|hexstringDec (ASSIGN HEXSTRING_LITERAL)*?
		|octetstringDec (ASSIGN OCTETSTRING_LITERAL)*?
		|charDec (ASSIGN CHAR_LITERAL)*?
		|charstringDec (ASSIGN CHARSTRING_LITERAL)*?
		|objidDec
		) 
	;
constDef
	:'const' 
		(intDec ASSIGN INTEGER_LITERAL
		|floatDec ASSIGN FLOAT_LITERAL
		|booleanDec ASSIGN BOOLEAN_LITERAL
		|bitstringDec ASSIGN BITSTRING_LITERAL
		|hexstringDec ASSIGN HEXSTRING_LITERAL
		|octetstringDec ASSIGN OCTETSTRING_LITERAL
		|charDec ASSIGN CHAR_LITERAL
		|charstringDec ASSIGN CHARSTRING_LITERAL
		) 
	|'external' 'const'
		(intDec
		|floatDec
		|booleanDec
		|bitstringDec
		|hexstringDec
		|octetstringDec
		|charDec
		|charstringDec
		) 
	;